package com.example.user.controller.basic;

import com.example.framework.common.pojo.R;
import com.example.user.controller.basic.vo.HeartbeatReqVO;
import com.example.user.service.user.HeartbeatService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@Tag(name = "用户心跳")
@RestController
public class HeartbeatController {

    @Resource
    private HeartbeatService heartbeatService;

    @Operation(summary = "接收用户心跳")
    @PostMapping("/heartbeat")
    public R<String> receiveHeartbeat(@RequestBody HeartbeatReqVO heartbeatReqVO) {
        heartbeatService.receiveHeartbeat(heartbeatReqVO);
        return R.success("Heartbeat received");
    }

    @Operation(summary = "查询客户端状态")
    @GetMapping("/client/{clientId}/status")
    public R<Long> getClientStatus(@PathVariable String clientId) {
        Long lastSeen = heartbeatService.getClientStatus(clientId);
        return R.success(lastSeen);
    }

}